package com.dandelion.commons.utils;

import javax.servlet.http.HttpServletRequest;

public class IpUtil {
	
	/**
	 * 获得用户远程地址
	 */
	public static String getRemoteAddr(HttpServletRequest request){
		String remoteAddr = request.getHeader("X-Real-IP");
		
        if (StringUtils.isNotBlank(remoteAddr)) {
        	remoteAddr = request.getHeader("X-Forwarded-For");
        }else if (StringUtils.isNotBlank(remoteAddr)) {
        	remoteAddr = request.getHeader("Proxy-Client-IP");
        }else if (StringUtils.isNotBlank(remoteAddr)) {
        	remoteAddr = request.getHeader("WL-Proxy-Client-IP");
        }else if (request.getRemoteAddr().equals("0:0:0:0:0:0:0:1")) {
        	remoteAddr = "127.0.0.1";
        }
        return remoteAddr != null ? remoteAddr : request.getRemoteAddr();
	}

}
